Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic
Imports Microsoft.VisualBasic.PowerPacks
Friend Class frmXSheet
	Inherits System.Windows.Forms.Form
	
	Dim ExposureText As String 'holds the text from the exposure sheet
	Dim NumLinesExposure As Integer 'The number of lines in the exposure sheet
	
	Private Sub frmXSheet_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Call PositionExposureSheet()
	End Sub
	Private Sub lstXSheet_Scroll() 'The user is scrolling the X sheet
		
		
	End Sub
	
	Private Sub lstXSheet_MouseUp(ByRef Button As Short, ByRef Shift As Short, ByRef X As Single, ByRef Y As Single)
		
	End Sub
	
	
	Public Sub PositionExposureSheet() 'reposition / resize the X sheet relative to the Parent form
		Me.Top = 0
		Me.Left = 0
		Me.Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(frmMainForm.Height) - (TitleHeight * 2 * VB6.TwipsPerPixelY)) 'Set the x sheet height (This value is calculated in twips)
		Me.Width = VB6.TwipsToPixelsX(XsheetWidth * VB6.TwipsPerPixelX)
		'set the listbox heights
		Me.lstXNum.Height = (VB6.PixelsToTwipsY(Me.Height) / VB6.TwipsPerPixelY) - TitleHeight - cmdMouthShape.Height - 3
		Me.lstExposure.Height = (VB6.PixelsToTwipsY(Me.Height) / VB6.TwipsPerPixelY) - TitleHeight - cmdMouthShape.Height - 3
		' frmXSheet.picMouthShape.top = (frmXSheet.Height / Screen.TwipsPerPixelY) - TitleHeight - frmXSheet.picMouthShape.Height
		Me.picMouthShape.Top = lstExposure.Height + lstExposure.Top - Me.picMouthShape.Height
		Me.picMouthShape.Left = lstExposure.Left
		Call FillExposureSheetArray() 'Fill the array with data from the file
		Call ReloadExposureSheet(ExposureTopPos)
	End Sub
	
	Public Sub ReloadExposureSheet(ByRef TopPos As Integer) 'Reloads the exposure sheet with the relevant data. TopPos is the frame number of the top line
		'so to start printing at line 10 set this value to 10
		Dim X As Integer
		Dim FrameIDno As String
		
		Me.txtOffset.Text = CStr(XSheetOffset) 'set the xsheetoffset display
		Call MouthShapeSwitch() 'If the user has selected no display of mouth then switch it off or on etc.
		
		
		
		Me.lstXNum.Items.Clear() 'Clear the left number list
		NumLinesExposure = (Me.lstXNum.Height / 13) 'Each line in x sheet requires 13 pixels
		For X = TopPos To CInt(NumLinesExposure + TopPos - 1) 'Fill it with the initial position data
			FrameIDno = CStr(X)
			If Len(FrameIDno) = 1 Then FrameIDno = "00000" & FrameIDno
			If Len(FrameIDno) = 2 Then FrameIDno = "0000" & FrameIDno
			If Len(FrameIDno) = 3 Then FrameIDno = "000" & FrameIDno
			If Len(FrameIDno) = 4 Then FrameIDno = "00" & FrameIDno
			If Len(FrameIDno) = 5 Then FrameIDno = "0" & FrameIDno
			Me.lstXNum.Items.Add(FrameIDno)
		Next X
		
		'Reload and print the phoneme list
		lstExposure.Items.Clear()
		If XSheetName = "No X Sheet Selected" Or XSheetName = "" Then
			ReDim Phoneme(0) 'the file doesn't exist so just clear the array and exit
		Else
			If UBound(Phoneme) < 1 Then Call FillExposureSheetArray() 'the xsheet is named, but the phoneme array hasnt been filled yet
			For X = TopPos + XSheetOffset To NumLinesExposure + TopPos - 1 + XSheetOffset
				If X = 0 Then 'The zero frame is showing, so add padding in phoneme sheet
					lstExposure.Items.Add("------------")
				Else
					If X - 1 > UBound(Phoneme) Then GoTo EndofExposureList : 'There isnt sufficient data to fill all lines in the x sheet so leave early
					lstExposure.Items.Add(Phoneme(X - 1)) 'add the item to the phoneme list. -1 because phoneme array starts at zero not 1
				End If
			Next X
EndofExposureList: 
		End If
		
		
		
		
		
	End Sub
	Public Sub FillExposureSheetArray() 'Fills the array with data from the phoneme file
		
		If XSheetName = "No X Sheet Selected" Then
			ReDim Phoneme(0) 'the file doesn't exist so just clear the array and exit
			Exit Sub
		End If
		
		'UPGRADE_WARNING: Dir has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
		If Dir(XSheetName) <> "" Then 'Check if phoneme file exists
			ReDim Phoneme(0)
			FileOpen(23, XSheetName, OpenMode.Input)
			Do Until (EOF(23) = True)
				ReDim Preserve Phoneme(UBound(Phoneme) + 1)
				ExposureText = LineInput(23) 'Inputs a complete line from the phoneme file regardless of commas.
				Phoneme(UBound(Phoneme) - 1) = ExposureText 'Places the string at the end of the array
			Loop 
			FileClose(23)
			
		End If
	End Sub
	Public Sub MouthShapeSwitch() 'Toggles the mouth shape image on or off
		If MouthShapeOnOff = False Then
			picMouthShape.Visible = False 'Hide the mouth phoneme display
		Else
			picMouthShape.Visible = True 'Show the mouth phoneme display
		End If
	End Sub
	Public Sub LoadMouthShape(ByRef XSheetText As String) 'Draw the mouthshape. Supply this sub with the full line of text from the exposure sheet
		Dim XPos As Integer
		Dim Ypos As Integer
		XPos = 800 : Ypos = 200 'set the "rest" image to be printed by default
		
		If VB.Left(XSheetText, 4) = "[AI]" Or VB.Left(VB6.GetItemString(Me.lstExposure, 1), 4) = "[ai]" Then
			XPos = 0 : Ypos = 0
			GoTo ReadyToPrint
		End If
		
		If VB.Left(XSheetText, 3) = "[O]" Or VB.Left(VB6.GetItemString(Me.lstExposure, 1), 3) = "[o]" Then
			XPos = 200 : Ypos = 0
			GoTo ReadyToPrint
		End If
		
		If VB.Left(XSheetText, 3) = "[E]" Or VB.Left(VB6.GetItemString(Me.lstExposure, 1), 3) = "[e]" Then
			XPos = 400 : Ypos = 0
			GoTo ReadyToPrint
		End If
		
		If VB.Left(XSheetText, 3) = "[U]" Or VB.Left(VB6.GetItemString(Me.lstExposure, 1), 3) = "[u]" Then
			XPos = 600 : Ypos = 0
			GoTo ReadyToPrint
		End If
		
		If VB.Left(XSheetText, 6) = "[ETC.]" Or VB.Left(XSheetText, 6) = "[etc.]" Or VB.Left(XSheetText, 5) = "[ETC]" Or VB.Left(XSheetText, 5) = "[etc]" Then
			XPos = 800 : Ypos = 0
			GoTo ReadyToPrint
		End If
		
		If VB.Left(XSheetText, 3) = "[L]" Or VB.Left(XSheetText, 3) = "[l]" Then
			XPos = 0 : Ypos = 200
			GoTo ReadyToPrint
		End If
		
		If VB.Left(XSheetText, 4) = "[WQ]" Or VB.Left(XSheetText, 4) = "[wq]" Then
			XPos = 200 : Ypos = 200
			GoTo ReadyToPrint
		End If
		
		If VB.Left(XSheetText, 5) = "[MBP]" Or VB.Left(XSheetText, 5) = "[mbp]" Then
			XPos = 400 : Ypos = 200
			GoTo ReadyToPrint
		End If
		
		If VB.Left(XSheetText, 4) = "[FV]" Or VB.Left(XSheetText, 4) = "[fv]" Then
			XPos = 600 : Ypos = 200
			GoTo ReadyToPrint
		End If
ReadyToPrint: 

        Dim shapeGraph As Graphics = Me.picMouthShape.CreateGraphics
        Dim shapehdc As IntPtr = shapeGraph.GetHdc
        Dim avgGraph As Graphics = frmAveraging.picMouthShapes.CreateGraphics
        Dim avghdc As IntPtr = avgGraph.GetHdc

		'UPGRADE_ISSUE: Constant vbSrcCopy was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="55B59875-9A95-4B71-9D6A-7C294BF7139D"'
		'UPGRADE_ISSUE: PictureBox property picMouthShapes.hdc was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
		'UPGRADE_ISSUE: PictureBox property picMouthShape.hdc was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC4C7EC0-C903-48FC-ACCC-81861D12DA4A"'
        Call BitBlt(shapehdc, 0, 0, 200, 200, avghdc, XPos, Ypos, vbSrcCopy) 'blit the image to the screen

        shapeGraph.ReleaseHdc(shapehdc)
        shapeGraph.Dispose()
        avgGraph.ReleaseHdc(avghdc)
        avgGraph.Dispose()

        Me.picMouthShape.Refresh()
	End Sub
End Class